<template>
  <div class="home-product" ref="target">
    <transition name="fade">
      <div v-if="list.length">
        <HomePanel :title="item.name" v-for="item in list" :key="item.id">
          <template #right>
            <div class="sub">
              <RouterLink
                v-for="item2 in item.children"
                :key="item2.id"
                to="/"
                >{{ item2.name }}</RouterLink
              >
            </div>
            <XtxMore />
          </template>
          <div class="box">
            <RouterLink class="cover" to="/">
              <img v-src="item.picture" alt="" />
              <strong class="label">
                <span>{{ item.name }}馆</span>
                <span>{{ item.saleInfo }}</span>
              </strong>
            </RouterLink>
            <ul class="goods-list">
              <li v-for="item3 in item.goods" :key="item3.id">
                <HomeGoods :goods="item3" />
              </li>
            </ul>
          </div>
        </HomePanel>
      </div>
      <div v-else>
        <div class="skeleton" v-for="j in 4" :key="j">
          <div class="header">
            <XtxSkeleton
              class="headLeftItem"
              width="240px"
              height="35px"
              bg="#e4e4e4"
            ></XtxSkeleton>
            <XtxSkeleton
              class="headRightItem"
              width="520px"
              height="35px"
              bg="#e4e4e4"
            ></XtxSkeleton>
          </div>
          <div class="body">
            <XtxSkeleton
              class="leftItem"
              width="240px"
              height="610px"
              bg="#e4e4e4"
            ></XtxSkeleton>
            <div class="items">
              <XtxSkeleton
                class="item"
                v-for="i in 8"
                :key="i"
                width="240px"
                height="300px"
                bg="#e4e4e4"
              ></XtxSkeleton>
            </div>
          </div>
        </div>
      </div>
    </transition>
  </div>
</template>

<script>
import HomePanel from './home-panel'
import HomeGoods from './home-goods'
import { useLazyData } from '@/hooks'
import { findGoods } from '@/api/home'
export default {
  name: 'HomeProduct',
  components: { HomePanel, HomeGoods },
  setup () {
    const { target, list } = useLazyData(findGoods)
    // console.log(list)
    return { target, list }
  }
}
</script>

<style scoped lang='less'>
.home-product {
  background: #fff;
  height: 2900px;
  // width: 100%;
  .sub {
    margin-bottom: 2px;
    a {
      padding: 2px 12px;
      font-size: 16px;
      border-radius: 4px;
      &:hover {
        background: @xtxColor;
        color: #fff;
      }
      &:last-child {
        margin-right: 80px;
      }
    }
  }
  .box {
    display: flex;
    .cover {
      width: 240px;
      height: 610px;
      margin-right: 10px;
      position: relative;
      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
      .label {
        width: 188px;
        height: 66px;
        display: flex;
        font-size: 18px;
        color: #fff;
        line-height: 66px;
        font-weight: normal;
        position: absolute;
        left: 0;
        top: 50%;
        transform: translate3d(0, -50%, 0);
        span {
          text-align: center;
          &:first-child {
            width: 76px;
            background: rgba(0, 0, 0, 0.9);
          }
          &:last-child {
            flex: 1;
            background: rgba(0, 0, 0, 0.7);
          }
        }
      }
    }
    .goods-list {
      width: 990px;
      display: flex;
      flex-wrap: wrap;
      li {
        width: 240px;
        height: 300px;
        margin-right: 10px;
        margin-bottom: 10px;
        &:nth-last-child(-n + 4) {
          margin-bottom: 0;
        }
        &:nth-child(4n) {
          margin-right: 0;
        }
      }
    }
  }
}
.skeleton {
  position: relative;
  width: 1240px;
  margin: 0 auto;
  .header {
    display: flex;
    justify-content: space-between;
    padding: 40px 0;
  }
  .body {
    display: flex;
    .leftItem {
      margin-right: 10px;
    }
    .items {
      flex: 1;
      display: flex;
      width: 990px;
      flex-wrap: wrap;
      //  background-color: red;
      .item {
        width: 240px;
        height: 300px;
        margin-right: 10px;
        margin-bottom: 10px;
        &:nth-last-child(-n + 4) {
          margin-bottom: 0;
        }
        &:nth-child(4n) {
          margin-right: 0;
        }
      }
    }
  }
}
</style>
